#include<bits/stdc++.h>
using namespace std;
float ttl;
int n1, n2, n3, p1, p2, p3, sum_min, sum_temp;
void sum_ttl(int sum_n1, int sum_n2, int sum_n3, int sum_p1, int sum_p2, int sum_p3) {
//	int r1 = p1 / n1, r2 = p2 / n2, r3 = p3 / n3;
//	int x = r1 + r2 + r3;
//	r1 = max(r1, r2, r3);
//	r3 = min(r1, r2, r3);
//	r2 = x - r1 - r2;
	float ttl_temp = ttl;
	sum_temp += ttl_temp / sum_n3 * sum_p3;
	ttl_temp -= ttl_temp / sum_n3;
	sum_temp += ttl_temp / sum_n2 * sum_p2;
	ttl_temp -= ttl_temp / sum_n2;
	sum_temp += ttl_temp / sum_n1 * sum_p1;
	ttl_temp -= ttl_temp / sum_n1;
}
int main() {

	scanf("%f %d %d %d %d %d %d", &ttl, &n1, &p1, &n2, &p2, &n3, &p3);
	sum_min = ceil((ttl / n1))  * p1;
	sum_temp = ceil((ttl / n2)) * p2;
	if (sum_temp < sum_min) sum_min = sum_temp;
	sum_temp = ceil((ttl / n3)	) * p3;
	if (sum_temp < sum_min) sum_min = sum_temp;
	sum_ttl(n1, n2, n3, p1, p2, p3);
	if (sum_temp < sum_min) sum_min = sum_temp;
	sum_ttl(n1, n3, n2, p1, p3, p2);
	if (sum_temp < sum_min) sum_min = sum_temp;
	sum_ttl(n2, n1, n3, p2, p1, p3);
	if (sum_temp < sum_min) sum_min = sum_temp;
	sum_ttl(n2, n3, n1, p2, p3, p1);
	if (sum_temp < sum_min) sum_min = sum_temp;
	sum_ttl(n3, n2, n1, p3, p2, p1);
	if (sum_temp < sum_min) sum_min = sum_temp;
	sum_ttl(n3, n1, n2, p3, p2, p1);
	if (sum_temp < sum_min) sum_min = sum_temp;

	printf("%.f", ceil(sum_min));
	return 0;
}
